package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.wemedia.dtos.comment.WmCommentDto;
import com.heima.wemedia.dtos.comment.WmCommentLikeDto;
import com.heima.wemedia.dtos.comment.WmNewsCommentDto;
import com.heima.wemedia.service.WmCommentService;
import com.heima.wemedia.vos.comment.WmCommentDetailsVo;
import com.heima.wemedia.vos.comment.WmCommentVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/comment/manage")
@Slf4j
public class WmCommentController {

    @Autowired
    private WmCommentService wmCommentService;

    /**
     * 查看评论列表
     *
     * @param wmNewsCommentDto 前端dto
     * @return 返回结果
     */
    @PostMapping("/find_news_comments")
    public PageResponseResult findNewsComments(@RequestBody WmNewsCommentDto wmNewsCommentDto) {
        log.info("wmNewsCommentDto:{}", wmNewsCommentDto);
        Page<WmCommentVo> page = wmCommentService.findNewsComments(wmNewsCommentDto);
        return PageResponseResult.getPageResponseResult(page);
    }

    /**
     * 打开或关闭评论
     *
     * @param wmCommentDto 前端dto
     * @return 返回结果
     */
    @PostMapping("/update_comment_status")
    public ResponseResult updateCommentStatus(@RequestBody WmCommentDto wmCommentDto) {
        wmCommentService.updateCommentStatus(wmCommentDto);
        return ResponseResult.okResult(null);
    }

    /**
     * 查看评论详情信息
     *
     * @param wmNewsCommentDto 前端dto
     * @return 返回结果
     */
    @PostMapping("/list")
    public ResponseResult<List<WmCommentDetailsVo>> list(@RequestBody WmNewsCommentDto wmNewsCommentDto) {
        List<WmCommentDetailsVo> wmCommentDetailsVos = wmCommentService.list(wmNewsCommentDto);
        return ResponseResult.okResult(wmCommentDetailsVos);
    }

    /**
     * 回复评论
     *
     * @param wmNewsCommentDto 前端dto
     * @return 返回结果
     */
    @PostMapping("/comment_repay")
    public ResponseResult commentRepay(@RequestBody WmNewsCommentDto wmNewsCommentDto) {
        log.info("回复评论功能wmNewsCommentDto:{}", wmNewsCommentDto);
        wmCommentService.commentRepay(wmNewsCommentDto);
        return ResponseResult.okResult(null);
    }

    /**
     * 评论点赞
     *
     * @param wmCommentLikeDto 前端dto信息
     * @return 返回结果
     */
    @PostMapping("/like")
    public ResponseResult<Map<String, Integer>> like(@RequestBody WmCommentLikeDto wmCommentLikeDto) {
        log.info("评论点赞功能wmCommentLikeDto:{}", wmCommentLikeDto);
        Map<String, Integer> data = wmCommentService.like(wmCommentLikeDto);
        return ResponseResult.okResult(data);
    }

    /**
     * 删除评论
     *
     * @param commentId 评论id
     * @return 返回结果
     */
    @DeleteMapping("/del_comment/{commentId}")
    public ResponseResult delComment(@PathVariable String commentId) {
        log.info("删除文章评论功能commentId:{}", commentId);
        wmCommentService.delComment(commentId);
        return ResponseResult.okResult(null);
    }

    /**
     * 删除评论回复
     *
     * @param commentRepayId 评论回复id
     * @return 返回结果
     */
    @DeleteMapping("/del_comment_repay/{commentRepayId}")
    public ResponseResult delCommentRepay(@PathVariable String commentRepayId) {
        log.info("删除评论回复功能commentRepayId:{}", commentRepayId);
        wmCommentService.delCommentRepay(commentRepayId);
        return ResponseResult.okResult(null);
    }
}
